package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.editDepotBean;
import com.ymatou.iapi.godmch.service.createDepotCall;
import com.ymatou.iapi.godmch.service.editDepotCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.model.godmch.mch_depot_infoExample;
import com.ymttest.database.sqlwapper.godmch.mch_depot_infoWapper;
import com.ymttest.utils.TestDataManager;
/**
*编辑仓库信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_editDepot{
	private static editDepotBean bean;
	private static editDepotCall call;
	
	createDepotBean cbean=new createDepotBean ();
	createDepotCall ccall=new createDepotCall();
    	
	mch_depot_infoWapper depotWapper;
	mch_depot_infoExample example;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("编辑仓库信息");
	}

	@Before
	public void caseUp() {
		bean=new editDepotBean();
		call=new editDepotCall();
		depotWapper=new mch_depot_infoWapper();
		example=new mch_depot_infoExample();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify() throws InterruptedException {
		
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		example.clear();
		example.createCriteria().andMchIdEqualTo(bean.getMchId()).andDepotIdEqualTo(bean.getDepotId());
		mch_depot_info  depot=depotWapper.selectByExample(example).get(0);
       	Logger.verifyEquals(bean.getDepotTitle(), depot.getDepotTitle(), "验证数据库字段DepotTitle与传入的是否一致");
    	Logger.verifyEquals(bean.getRemark(), depot.getRemark(), "验证数据库字段Remark与传入的是否一致");
    	Logger.verifyEquals(0, depot.getDepotStatus(), "验证数据库字段DepotStatus=0");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editDepot_001() {
		Logger.start(true,"编辑仓库信息--验证正常场景");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			createDepotBean createDepotBean=GodmchManageCallService.createDepot(mchId);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			bean.setMchId(mchId);
			bean.setDepotId(info.getDepotId());
			bean.setDepotTitle("修改仓库名称_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			bean.setBuyerTitle("BuyerTitle_"+TestDataManager.getRandomNum(5));
			bean.setPicUrl("http://www.baidu.com_"+TestDataManager.getRandomNum(5));
			call.setData(bean);
			call.callService();	
			
			check_verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editDepot_002() {
		Logger.start(true,"编辑仓库信息--验证相同商户仓库名称与修改的一致-返回成功");
		try {
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			createDepotBean createDepotBean=GodmchManageCallService.createDepot(mchId);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			bean.setMchId(mchId);
			bean.setDepotId(info.getDepotId());
			bean.setDepotTitle(info.getDepotTitle());
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editDepot_002_1() {
		Logger.start(true,"编辑仓库信息--验证相同商户仓库名称重复-返回失败");
		try {
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			createDepotBean createDepotBean=GodmchManageCallService.createDepot(mchId);
			
			cbean.setMchId(mchId);
	    	cbean.setDepotTitle("仓库名称_"+TestDataManager.getRandomIntNum(5));
	    	cbean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
	    	ccall.setData(cbean);
	    	ccall.callService();	
			
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			bean.setMchId(mchId);
			bean.setDepotId(info.getDepotId());
			bean.setDepotTitle(cbean.getDepotTitle());//第二个仓库与第一个仓库重复
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editDepot_002_2() {
		Logger.start(true,"编辑仓库信息--验证相同买家端显示名称重复-返回失败");
		try {
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			createDepotBean createDepotBean=GodmchManageCallService.createDepot(mchId);
			
			cbean.setMchId(mchId);
	    	cbean.setDepotTitle("仓库名称_"+TestDataManager.getRandomIntNum(5));
	    	cbean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
	    	bean.setBuyerTitle("买家端显示名称_"+TestDataManager.getRandomNum(5));
			bean.setPicUrl("http://www.baidu.com_"+TestDataManager.getRandomNum(5));
	    	ccall.setData(cbean);
	    	ccall.callService();	
			
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			bean.setMchId(mchId);
			bean.setDepotId(info.getDepotId());
			bean.setDepotTitle(cbean.getDepotTitle());//第二个仓库与第一个仓库重复
		    bean.setBuyerTitle(cbean.getBuyerTitle());
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editDepot_003_1() {
		Logger.start(true,"编辑仓库信息--验证mchId与DepotId不一致");
		try {
			Integer mchId1 = GodmchManageCallService.CreateSellerMch();
			Integer mchId2 = GodmchManageCallService.CreateSellerMch();
			createDepotBean createDepotBean=GodmchManageCallService.createDepot(mchId1);
			
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId1);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			bean.setMchId(mchId2);
			bean.setDepotId(info.getDepotId());
			bean.setDepotTitle("修改仓库名称_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("修改仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editDepot_003() {
		Logger.start(true,"编辑仓库信息--验证mchId为空");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			createDepotBean createDepotBean=GodmchManageCallService.createDepot(mchId);
			
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			//bean.setMchId(mchId2);
			bean.setDepotId(info.getDepotId());
			bean.setDepotTitle("修改仓库名称_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("修改仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editDepot_004() {
		Logger.start(true,"编辑仓库信息--验证depotId为空");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			
			bean.setMchId(mchId);
			//bean.setDepotId(info.getDepotId());
			bean.setDepotTitle("修改仓库名称_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("修改仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editDepot_005() {
		Logger.start(true,"编辑仓库信息--验证depotTitle为空");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			createDepotBean createDepotBean=GodmchManageCallService.createDepot(mchId);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			bean.setMchId(mchId);
			bean.setDepotId(info.getDepotId());
			//bean.setDepotTitle("修改仓库名称_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}